<?php
/**
 * Created by PhpStorm.
 * User: zhangxinke
 * Date: 2019/6/1
 * Time: 21:58
 */

namespace app\api\controller;

use app\api\model\OrderModel;

class Order extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->order = new OrderModel();
    }
    public function AjaxReturn($code,$msg,$data=array())
    {

        $returnData=array(
            "code"=>$code
        );
        if($msg)
        {
            $returnData["message"]=$msg;
        }
        if(!empty($data))
        {
            $returnData["data"]=$data;
        }
        exit(json_encode($returnData));
    }
    public function orderlist(){//商品列表的显示
        $list=$this->order->index();
      	if(!empty($list)){
        	return $this->AjaxReturn("1",'操作成功',$list);
        }else{
        	return $this->AjaxReturn("0",'暂无数据',$list);
        }
        
    }
  	public function search(){//商品列表的显示
        $list=$this->order->search();
      	if(!empty($list)){
        	return $this->AjaxReturn("1",'操作成功',$list);
        }else{
        	return $this->AjaxReturn("0",'暂无数据',$list);
        }
        
    }
  
  	public function type(){//查询店铺类型
     $list=$this->order->type();
        if(!empty($list)){
            return $this->AjaxReturn("1",'操作成功',$list);
        }else{
            return $this->AjaxReturn("2",'操作失败');
        }
    }
    public function ordercheck(){//订单的详细页面
        $res=$this->order->ordercheck();
        $res['img']=explode(',',$res['img']);
      	$res['synopsis']=explode(',',$res['synopsis']);
        if(!empty($res)){
            return $this->AjaxReturn("1",'操作成功',$res);
        }else{
            return $this->AjaxReturn("2",'操作失败');
        }
    }
    public function Confirmorder(){//确认订单
        $uid=$this->uid;
        if ($uid==''){
            return $this->AjaxReturn("-1",'操作成功');
        }
        $res=$this->order->Confirmorder($uid);
        if($res==1){
            return $this->AjaxReturn("1",'操作成功');
        }elseif($res==2){
            return $this->AjaxReturn("12",'数据不能为null');
        }elseif($res==3){
            return $this->AjaxReturn("12",'用户余额不足');
        }elseif($res==4){
            return $this->AjaxReturn("12",'商店不足');
        }
    }
  	public function address(){
    	$uid=$this->uid;//dump($uid);die;
      	$res=$this->order->address($uid);
      	if(!empty($res)){
            return $this->AjaxReturn("1",'操作成功',$res);
        }else{
            return $this->AjaxReturn("2",'没有默认地址');
        }
    }
  	public function order_list(){//订单列表
    	$uid=$this->uid;
        $res=$this->order->order_list($uid);
      	foreach($res as $k=>$val){
          $res[$k]['createtime']=date('Y-m-d',$res[$k]['createtime']);
        }
      	if(!empty($res)){
            return $this->AjaxReturn("1",'查询成功',$res);
        }else{
            return $this->AjaxReturn("2",'没有订单');
        }
    }
    public function order_check(){//订单列表
     	$uid=$this->uid;
        $res=$this->order->order_check($uid);
      	if(!empty($res)){
            return $this->AjaxReturn("1",'查询成功',$res);
        }else{
            return $this->AjaxReturn("2",'没有默认地址');
        }
    }
    public function complete(){//完成订单
        $uid=$this->uid;
        $res=$this->order->complete($uid);
        if($res==1){
            return $this->AjaxReturn("1",'操作成功');
        }else{
            return $this->AjaxReturn("2",'操作失败');
        }
    }

}